package cn.weekimwee.firstlineofcodeforkotlin.unit3

import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.StaggeredGridLayoutManager
import cn.weekimwee.firstlineofcodeforkotlin.BaseActivity
import cn.weekimwee.firstlineofcodeforkotlin.R
import kotlinx.android.synthetic.main.activity_recycler_view.*
import org.jetbrains.anko.toast

class RecyclerViewActivity : BaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_recycler_view)
        val fruitList = arrayListOf(
                Fruit(id = R.mipmap.ic_launcher_round,name = "苹果".getRandomLenthName()),
                Fruit(id = R.mipmap.ic_launcher_round,name = "梨".getRandomLenthName()),
                Fruit(id = R.mipmap.ic_launcher_round,name = "杏".getRandomLenthName()),
                Fruit(id = R.mipmap.ic_launcher_round,name = "西瓜".getRandomLenthName()),
                Fruit(id = R.mipmap.ic_launcher_round,name = "李子".getRandomLenthName()),
                Fruit(id = R.mipmap.ic_launcher_round,name = "山竹".getRandomLenthName()),
                Fruit(id = R.mipmap.ic_launcher_round,name = "香蕉".getRandomLenthName()),
                Fruit(id = R.mipmap.ic_launcher_round,name = "榴莲".getRandomLenthName()),
                Fruit(id = R.mipmap.ic_launcher_round,name = "甘蔗".getRandomLenthName()),
                Fruit(id = R.mipmap.ic_launcher_round,name = "菠萝".getRandomLenthName()),
                Fruit(id = R.mipmap.ic_launcher_round,name = "柿子".getRandomLenthName()),
                Fruit(id = R.mipmap.ic_launcher_round,name = "荔枝".getRandomLenthName()),
                Fruit(id = R.mipmap.ic_launcher_round,name = "火龙果".getRandomLenthName()),
                Fruit(id = R.mipmap.ic_launcher_round,name = "龙眼".getRandomLenthName()),
                Fruit(id = R.mipmap.ic_launcher_round,name = "菠萝蜜".getRandomLenthName())

        )
        recycler_view.apply {
//            layoutManager = LinearLayoutManager(this@RecyclerViewActivity).apply { orientation = LinearLayoutManager.HORIZONTAL }
            //瀑布流
            layoutManager = StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL)
            val adapterFruit = FruitAdapter()
            adapterFruit.data = fruitList
            adapterFruit.onItemClick = { fruit ->toast("${fruit?.name}") }
            adapter = adapterFruit

        }
    }
}
